from fastapi import APIRouter, Depends

from common.utils import verif_oauth
from schemas.address import AddressSchemaInput
from service.address import AddressService

address_router = APIRouter(tags=[
    '收获地址'
])


@address_router.post("/address", summary='新增用户地址')
async def add_address(address_input: AddressSchemaInput):
    return await AddressService.add_address(address_input)


@address_router.delete("/address/{pk}", summary='删除用户地址')
async def del_address(pk: int):
    return await AddressService.del_address(pk)


@address_router.get("/address", summary='用户地址列表')
async def arr_address(token=Depends(verif_oauth)):
    return await AddressService.address_arr(token["id"])


@address_router.put("/address/{pk}", summary='更新用户地址')
async def update_address(pk: int, address_input: AddressSchemaInput):
    return await AddressService.put_address(pk, address_input)

@address_router.put("/address/default/{pk}", summary='修改默认地址')
async def default_address(pk: int, token=Depends(verif_oauth)):
    return await AddressService.default_set(pk, token["id"])